
<script src="<?php xcho(loadSource('/assets/plugins/underscore/underscore.min.js')) ?>"></script>
 <script>
    function getCurIndex(data,key,curVal){
        var _allVal = _.pluck(data,key),
            _inputVal = curVal,
            _curIndex = [],
            _dimResult = [];

        // value 跟输入的值完全一致
        _.each(data, function(item,index) {
            if ( item.name === curVal ) {
                _dimResult.push(item);
            }
        });

        // 没有完全一直，则一个字一个子匹配
        if ( _dimResult.length === 0 ) {
            _.each(_inputVal, function(val){
                _.each(_allVal, function(item,index) {
                    if (item.indexOf(val)>-1) {
                        _curIndex.push(index);
                    }
                })
            })
            // 去重
            _.each(_.uniq(_curIndex), function(item){
                _dimResult.push(data[item]);
            })
        }

        if ( _dimResult.length > 0 ) {
            return _dimResult;
        } else {
            return data;
        }
    }

 	getMessageCount();
    setInterval(function(){
        getMessageCount();
    },1000*60*5);

    function logoutFn() {
        $.messager.confirm('提示', '确定要退出吗?', function (r) {
            if (r) {
                $.messager.progress({
                    text: '正在退出中...'
                });
                window.location.href = localStorage.getItem('LOGOURHREF');
            }
        });
    }
    
 	function getMessageCount() {
        var url = "/ajax/message/getMessageCount";
        $.ajax({
            url: url,
            type: 'get',
            dataType: 'json',
            success: function (data) {
                if(data['success'] == 1) {
                    console.log(data['total'])
                    $("#message").text(data['total']);
                }
            },
            complete: function () {
            },
            error: function () {

            }
        });
    }
    $(function(){
        $('#top').addClass('fa fa-arrow-up').on('click', function(){
            $('body,html').animate({scrollTop:0},300);
        })
    })
 </script>
